﻿using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using DAO;
using System.Data;
using System.Data.SqlClient;
namespace BUS
{
    public class GetThongTinSearchBUS
    {
        public static DataTable GetThongTinSearch(GetThongTinSearchDTO tt, int nLoaiBN, SqlConnection conpk)
        {
            DataTable dtKQ = new DataTable();
            switch (nLoaiBN)
            {
                case 1://ngoai tru -- THUNGAN
                    {
                        dtKQ = GetThongTinSearchDAO.SearchNgoaiTru(tt, conpk);
                     
                        break;
                    }
                case 2://noi tru -- phkham
                    {
                        dtKQ = GetThongTinSearchDAO.SearchNoiTru(tt, conpk);
                       
                        break;
                    }
                case 3://mien giam -- phkham
                    {
                        dtKQ = DAO.GetThongTinSearchDAO.SearchChuongTrinh(tt, conpk, 1);
                        break;
                    }
                case 4://chuong trinh -- phkham
                    {
                        dtKQ = DAO.GetThongTinSearchDAO.SearchChuongTrinh(tt, conpk, 2);
                        break;
                    }
                case 5://KSK -- phkham
                    {
                        dtKQ = GetThongTinSearchDAO.SearchKSK(tt, conpk);
                       
                        break;
                    }
            } 
            if (dtKQ != null)
            {
                for (int i = 0; i < dtKQ.Rows.Count; i++)
                {
                    dtKQ.Rows[i]["tendvu"] =
                        Uit.it_Font.VNIToUnicode(dtKQ.Rows[i]["tendvu"].ToString());
                    if (nLoaiBN == 5)//KSK
                    {
                        dtKQ.Rows[i]["tendonvi"] =
                            Uit.it_Font.VNIToUnicode(dtKQ.Rows[i]["tendonvi"].ToString());
                    }
                    else if (nLoaiBN == 2 )//noi tru
                    {
                        dtKQ.Rows[i]["chandoan"] =
                            Uit.it_Font.VNIToUnicode(dtKQ.Rows[i]["chandoan"].ToString());
                        dtKQ.Rows[i]["PPMo"] =
                            Uit.it_Font.VNIToUnicode(dtKQ.Rows[i]["PPMo"].ToString());
                        dtKQ.Rows[i]["chatbp"] = Uit.it_Font.VNIToUnicode(dtKQ.Rows[i]["chatbp"].ToString());
                    }
                    else
                    {
                        dtKQ.Rows[i]["chandoan"] = dtKQ.Rows[i]["chandoan"].ToString();
                        dtKQ.Rows[i]["tendonvi"] = dtKQ.Rows[i]["tendonvi"].ToString();
                        dtKQ.Rows[i]["chatbp"] = dtKQ.Rows[i]["chatbp"].ToString();
                    }

                    //if (dtKQ.Rows[i]["Ngaycdmau"].ToString()== "")//KSK
                    //{
                    //    dtKQ.Rows[i]["NgGioCoDinh"] = "";
                    //}
                    //else if (dtKQ.Rows[i]["gioCDBP"].ToString() == "")//KSK
                    //{
                    //    dtKQ.Rows[i]["NgGioCoDinh"] = dtKQ.Rows[i]["Ngaycdmau"].ToString();
                    //}
                    //else
                    //{
                    //    dtKQ.Rows[i]["NgGioCoDinh"] = 
                    //        Convert.ToDateTime(dtKQ.Rows[i]["Ngaycdmau"].ToString()).ToString("yyyy-MM-dd")
                    //        + " "+dtKQ.Rows[i]["gioCDBP"].ToString();
                    //}

                    if ((Boolean)dtKQ.Rows[i]["gioi"])
                    {
                        dtKQ.Rows[i]["gioitinh"] = "Nam";
                    }
                    else
                    {
                        dtKQ.Rows[i]["gioitinh"] = "Nữ";
                    }
                    int namsinh = Convert.ToInt32(dtKQ.Rows[i]["namsinh"]);

                    dtKQ.Rows[i]["tuoi"] = DateTime.Today.Year - namsinh;
                    dtKQ.Rows[i]["Nghe"] = Uit.it_Font.VNIToUnicode(dtKQ.Rows[i]["Nghe"].ToString());
                    
                }
            }        
           
            return dtKQ;
        }
        
        public static DataTable GetMDDungDichCD()
        {
            return GetThongTinSearchDAO.GetMDDungDichCD();
        }

        public static DataTable SearchTuongTrinh(string SoHS, int LanMo, SqlConnection conpk)
        {
            return DAO.GetThongTinSearchDAO.SearchTuongTrinh(SoHS,  LanMo, conpk);
        }

        public static Boolean InsertTuongTrinh(string SoPT, int LanMo
                                            , string TuongTrinh, SqlConnection conpk)
        {
            return DAO.GetThongTinSearchDAO.InsertTuongTrinh(SoPT, LanMo, TuongTrinh, conpk);
        }

        public static Boolean UpdateTuongTrinh(string SoPT, int LanMo
                                            , string TuongTrinh, SqlConnection conpk)
        {
            return DAO.GetThongTinSearchDAO.UpdateTuongTrinh(SoPT, LanMo, TuongTrinh, conpk);
        }


        public static DataTable GetChiDinhThem(string SoTieuBan)
        {
            return DAO.GetThongTinSearchDAO.GetChiDinhThem(SoTieuBan);
        }

        public static DataTable GetChiDinhHoanTien(string SoTieuBan)
        {
            return DAO.GetThongTinSearchDAO.GetChiDinhHoanTien(SoTieuBan);
        }

        public static DataTable GetDSDaXacNhan(string tungay, string denngay,
                                                int nLoaiBN, int kq )
        {
            DataTable dtKQ = new DataTable();
                       
            dtKQ = DAO.GetThongTinSearchDAO.SearchDaXacNhan(tungay, denngay,
                                                 nLoaiBN, kq );
            if (dtKQ != null)
            {
                for (int i = 0; i < dtKQ.Rows.Count; i++)
                {
                    if ((Boolean)dtKQ.Rows[i]["gioi"])
                    {
                        dtKQ.Rows[i]["gioitinh"] = "Nam";
                    }
                    else
                    {
                        dtKQ.Rows[i]["gioitinh"] = "Nữ";
                    }
                    int namsinh = Convert.ToInt32(dtKQ.Rows[i]["namsinh"]);
                    dtKQ.Rows[i]["tuoi"] = DateTime.Today.Year - namsinh;
                    dtKQ.Rows[i]["tendvu"] = Uit.it_Font.VNIToUnicode(dtKQ.Rows[i]["tendvu"].ToString());

                }
            }
            return dtKQ;
        }

        public static DataTable SearchDaXacNhanBySoTB(string SoTieuBan)
        {
            DataTable dtKQ = new DataTable();

            dtKQ = DAO.GetThongTinSearchDAO.SearchDaXacNhanBySoTB(SoTieuBan);
            if (dtKQ != null)
            {
                for (int i = 0; i < dtKQ.Rows.Count; i++)
                {
                    if ((Boolean)dtKQ.Rows[i]["GioiTinh"])
                    {
                        dtKQ.Rows[i]["gioi"] = "Nam";
                    }
                    else
                    {
                        dtKQ.Rows[i]["gioi"] = "Nữ";
                    }
                    int namsinh = Convert.ToInt32(dtKQ.Rows[i]["namsinh"]);
                    dtKQ.Rows[i]["tuoi"] = DateTime.Today.Year - namsinh;
                    dtKQ.Rows[i]["tendvu"] = Uit.it_Font.VNIToUnicode(dtKQ.Rows[i]["tendvu"].ToString());
                }
            }
            return dtKQ;
        }

        public static DataTable GetDSPPNhuom()
        {
            return DAO.GetThongTinSearchDAO.GetDSPPNhuom();
        }
        public static DataTable SearchPhanLoaiDV(string DVuCode)
        {
            return DAO.GetThongTinSearchDAO.SearchPhanLoaiDV( DVuCode);
        }

        public static DataTable GetDSDaXacNhanKSK(string tungay, string denngay,
                                                int nLoaiBN, int kq)
        {
            DataTable dtKQ = new DataTable();

            dtKQ = DAO.GetThongTinSearchDAO.SearchDaXacNhanKSK(tungay, denngay,
                                                 nLoaiBN, kq);
            if (dtKQ != null)
            {
                for (int i = 0; i < dtKQ.Rows.Count; i++)
                {
                    if ((Boolean)dtKQ.Rows[i]["gioi"])
                    {
                        dtKQ.Rows[i]["gioitinh"] = "Nam";
                    }
                    else
                    {
                        dtKQ.Rows[i]["gioitinh"] = "Nữ";
                    }
                    int namsinh = Convert.ToInt32(dtKQ.Rows[i]["namsinh"]);
                    dtKQ.Rows[i]["tuoi"] = DateTime.Today.Year - namsinh;
                    
                    dtKQ.Rows[i]["tendvu"] = Uit.it_Font.VNIToUnicode(dtKQ.Rows[i]["tendvu"].ToString());
                    dtKQ.Rows[i]["tendonvi"] = Uit.it_Font.VNIToUnicode(dtKQ.Rows[i]["tendonvi"].ToString());
                }
            }
            return dtKQ;
        }

        public static DataTable SearchDSBacSi()
        {
            return GetThongTinSearchDAO.SearchDSBacSi();
        }

        public static DataTable SearchDSNguoiCatLoc()
        {
            DataTable dtrs =  GetThongTinSearchDAO.SearchDSBacSi();
            DataTable dtktv = GetThongTinSearchDAO.SearchDSKTV();
            dtrs.Merge(dtktv);
            return dtrs;
        }

        public static DataTable GetHMMD()
        {
            return GetThongTinSearchDAO.GetHMMD();
        }

        public static DataTable GetNhuomDB()
        {
            return GetThongTinSearchDAO.GetNhuomDB();
        }

        public static DataTable GetDMHoanTien()
        {
            return GetThongTinSearchDAO.GetDMHoanTien();
        }

        public static DataTable GetChiDinh(string SoHS, string SoBN, string DVuCode)
        {
            return GetThongTinSearchDAO.GetChiDinh(SoHS, SoBN, DVuCode);
        }

        public static DataTable GetChiDinhKhamBenh(string SoBN, string SoHS, string DVCode, SqlConnection conpk)
        {
            return GetThongTinSearchDAO.GetChiDinhKhamBenh(SoBN, SoHS, DVCode, conpk);
        }

        public static DataTable GetChiDinhCLS(string SoBN, string SoHS, SqlConnection conpk)
        {
            return GetThongTinSearchDAO.GetChiDinhCLS(SoBN, SoHS, conpk);
        }

        public static DataTable SearchDSBacSiCD()
        {
            return GetThongTinSearchDAO.SearchDSBacSiCD();
        }

        public static DataTable SearchDSKTV()
        {
            return GetThongTinSearchDAO.SearchDSKTV();
        }

        public static DataTable SearchPPMo()
        {
            DataTable dt = GetThongTinSearchDAO.SearchPPMo();
            if (dt != null)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    dt.Rows[i]["chidanh"] = Uit.it_Font.VNIToUnicode(dt.Rows[i]["chidanh"]);
                }
            }
            return dt;
        }

        public static DataTable SearchDonViGuiMau()
        {           
            return GetThongTinSearchDAO.SearchDonViGuiMau();
        }

        public static DataTable SearchDonVi(SqlConnection conpk)
        {
            return GetThongTinSearchDAO.SearchDonVi(conpk);
        }

        public static DataTable GetDsBenhPAP()
        {
            return GetThongTinSearchDAO.GetDsBenhPAP();
        }

        public static DataTable GetURLHinh(SqlConnection conpk)
        {
            return GetThongTinSearchDAO.GetURLHinh(conpk);
        }
    }
}
